# -*- coding: utf-8 -*-
# @Create_time   : :
# @Author        :kumiler
# @emial         :lukunming@jtexpress.com
# @File          :.py
# @Desc          : 每天删除指定天的历史数据和分区，控制无效数据及文件，不可调历史批次的任务


from datetime import timedelta, date
from airflow.operators.bash import BashOperator
from airflow.models import Variable

hive_user = 'hive'  # hive 客户端用户
hive_password = Variable.get('hive_password')  # hive 客户端密码
dim_dependent_dt_vaule = date.today() + timedelta(days=-180)  # 获取180天前的日期--删除第T-180天的分区及数据

drop_partition_jms_dim_dim_dependent = BashOperator(
    task_id='drop_partition_jms_dim_dim_dependent',
    execution_timeout=timedelta(minutes=10),
    email=['lukunming@jtexpress.com', 'yl_bigdata@yl-scm.com'],
    bash_command="jms_bigdata_platform/small_files_merger/drop_partition/drop_partition.sh",
    pool='spmi_piece',
    retries=0,
    pool_slots=1,
    params={'db': "jms_dim",
            'table': "dim_dependent",
            'partition_key': 'dt',
            'partition_vaule': dim_dependent_dt_vaule,
            'is_partition': 1,
            'hive_user': hive_user,
            'hive_password': hive_password
            }
)


dwd_wide_yl_rt_ssmx_bill_detail_hi_vaule = date.today() + timedelta(days=-7)  # 获取7天前的日期--删除第T-7天的分区及数据
drop_partition_jms_dwd_dwd_wide_yl_rt_ssmx_bill_detail_hi = BashOperator(
    task_id='drop_partition_jms_dwd_dwd_wide_yl_rt_ssmx_bill_detail_hi',
    execution_timeout=timedelta(minutes=15),
    email=['lukunming@jtexpress.com', 'yl_bigdata@yl-scm.com'],
    bash_command="jms_bigdata_platform/small_files_merger/drop_partition/drop_partition.sh",
    pool='spmi_piece',
    retries=0,
    pool_slots=1,
    params={'db': "jms_dwd",
            'table': "dwd_wide_yl_rt_ssmx_bill_detail_hi",
            'partition_key': 'dt',
            'partition_vaule': dwd_wide_yl_rt_ssmx_bill_detail_hi_vaule,
            'is_partition': 1,
            'hive_user': hive_user,
            'hive_password': hive_password
            }
)


